package threaddemo;

public class DeadLockDemo {

	
}
class Traine implements Runnable{
	private boolean flag;
	private Object water;
	private Object paper;
	
	public Traine() {
		super();
	}
	
	public Traine(boolean flag, Object water, Object paper) {
		super();
		this.flag = flag;
		this.water = water;
		this.paper = paper;
	}

	public void run(){
		if(flag){
			synchronized(water){
				wash(water);
				synchronized(paper){
					wipe(paper);
				}
			}
			
		}
		else{
			synchronized(paper){
				wipe(paper);
				synchronized(water){
					wash(water);
				}
			}
			
		}
	}
	
	private void wash(Object water){
		System.out.println(Thread.currentThread().getName()+water+" flows ");
		System.out.println(Thread.currentThread().getName()+" is washing ");
	}
	
	private void wipe(Object paper){
		System.out.println(Thread.currentThread().getName()+paper+" reducess ");
		System.out.println(Thread.currentThread().getName()+" is wiping ");
	}
	
}